package Algorithm;

import java.util.HashSet;
import java.util.Set;

public class LC3 {
    public int lengthOfLongestSubstring(String s) {
        if(s.length()==0) return 0;
        int i=0;
        int j=-1;
        int len=Integer.MIN_VALUE;
        Set<Character> set=new HashSet<>();
        while(j+1<s.length()){
            while(j+1<s.length() && !set.contains(s.charAt(j+1))){
                j++;
                set.add(s.charAt(j));
            }
            len=Math.max(len,j-i+1);
            set.remove(s.charAt(i));
            i++;
        }
        return len;
    }

}
